﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//--------------------------
using QLKTX1._0.DTO;
using QLKTX1._0.DB;
using System.Data.SqlClient;
using System.Data;
//---------------------------
namespace QLKTX1._0.DAO
{
    class LopDAO
    {
        public static List<LopDTO> dsLop()
        {
            List<LopDTO> dsLop = new List<LopDTO>();

            ConnectDB con = new ConnectDB();
            DataTable dt = con.getDataTable("SELECT * FROM Lop");

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                LopDTO lop = new LopDTO();

                lop.MaLop = Int32.Parse (dt.Rows[i]["maLop"].ToString());

                lop.TenLop = dt.Rows[i]["tenLop"].ToString();

                dsLop.Add(lop);
                
            }
            return dsLop ;
        }
        //Ham Insert
        public static bool themLop(LopDTO  lop)
        {

            ConnectDB con = new ConnectDB();// dung DB

            return con.executeQuery("INSERT INTO Lop(tenLop) VALUES('" + lop.TenLop  + "')");

        }
        //ham xoa 
        public static bool xoaLop(LopDTO lop)
        {
            ConnectDB con = new ConnectDB();
            return con.executeQuery("DELETE FROM Lop WHERE maLop='" + lop.MaLop + "' ");
        }
        //ham cap nhat 
        public static bool capNhatLop(LopDTO lop)
        {
            ConnectDB con = new ConnectDB();
            return con.executeQuery("UPDATE Lop set tenLop='" + lop.TenLop + "' WHERE maLop='" + lop.MaLop + "' ");
        }
    }
}
